<?php
define('IN_ADMINCP', TRUE);
define('IN_TESTCP', TRUE);
define('TESTCP_AJAX', AJAX);
define('TESTCP_PATH', dirname(__FILE__));
define('APP_PATH', dirname(TESTCP_PATH));
//echo TESTCP_PATH . '--' . APP_PATH;die;
require APP_PATH . '/app.php';

// $admincp = new admincp;
// $account = new admincp_account;
if($_SESSION['remark']!=3){
    header("location:http://oa/admin/login.php");
}
//上面的代码采用杨坤的框架，下面的代码采用原生PHP
include "center/Model.class.php";
include "center/Route.class.php";
class Index extends Model{
    public $show='';
    public function __construct(){
        //用户权限认证
    }
    public function Action(){
        //页面初始化数据
        $this->show=$this->Show();
    }
    public function Show(){
        $getPage=isset($_GET['page'])? $_GET['page']: 1;
        $dataPage=$this->Page('oa_article',30,$getPage);
        return array(
            'dataPage'=>$dataPage,
            'info'=>'删除分为单个删除和批量删除，删除后不可恢复请谨慎操作！',
            'title'=>'文章列表',
        );
    }
    //from:表单  num:每一页显示数据条数  page:当前页码
    public function Page($from,$num,$page){
        //一共可以分多少页面
        $numSql="SELECT COUNT(*) FROM $from";
        $numPage=ceil((parent::total($numSql))/$num);
        //查询请求页面的数据
        $limit=(($page-1)*$num).','.$num;
        $thisSql="SELECT * FROM $from ORDER BY id DESC LIMIT $limit";
        $thisPage=parent::all($thisSql);
        return array(
            'numPage'=>$numPage,//可以分多少也
            'thisPage'=>$thisPage,//当前分页数据
            'page'=>$page,//当前分页
            'num'=>$num,
            );
    }
}
$model=new Index();
$model->Action();
?>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <link rel="stylesheet" type="text/css" href="assets/css/show.css"/>
    <script type="text/javascript" src="assets/js/jquery-1.9.1.min.js"></script>
</head>
<body>
<div id="content">
    <div id="content-box">
        <div class="content-head" style="overflow:hidden">
            <div class="redirect">
                <a href="http://oa.heivr.com/download/show.php">资料库&nbsp;+</a>
            </div>
            <!-- <div class="keyboard padding-l40">
                <input type="text" class="search padding-l40 color-black" placeholder="站内搜索"/>
            
            </div> -->
        </div>
        <div class="content">
            <div class="box-head">
                <span class="width4">文章详情</span>
                <span class="width18">标题</span>
                <span class="width12">作者</span>
                <span class="width14">创建时间</span>
            </div>
            <ul id="list">
                <?php if($model->show['dataPage']):?>
                    <?php foreach($model->show['dataPage']['thisPage']as $k=>$v):?>
                        <li>
                            <a href="<?= Route::Url('details',['id'=>$v['id']])?>">
                            <p class="width4"><?= ($model->show['dataPage']['page']-1)*$model->show['dataPage']['num']+$k+1; ?></p>
                            <p class="width18"><?= $v['title'];?></p>
                            <p class="width12 red"><?= $v['admin'];?></p>
                            <p class="width14"><?= date('Y-m-d',$v['create_tim'])?></p>
                            </a>
                        </li>
                    <?php endforeach;?>
                <?php endif;?>
            </ul>
            <div class="box-footer">
                <ul class="page float-l">
                    <li><a class="page-l" target="_blank"></a></li>
                    <?php for($i=1;$i<=$model->show['dataPage']['numPage'];$i++):?>
                        <?php if($i==$model->show['dataPage']['page']):?>
                            <li><a href="<?= Route::Url('show',['page'=>$i]);?>" class="page-n page-click"><?= $i;?></a></li>
                        <?php else:?>
                            <li><a href="<?= Route::Url('show',['page'=>$i]);?>" class="page-n"><?= $i;?></a></li>
                        <?php endif;?>
                    <?php endfor;?>
                    <li><a class="page-r"></a></li>
                </ul>

            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //复选框点击样式
    var inputs=new Array();
    var id;
    $('.checkbox').on('click',function(){
        a=$(this).children('input').val();
        if(a==0){
            $(this).addClass('checkbox-on');
            $(this).removeClass('checkbox-off');
            $(this).children('input').val(1);
            id=$(this).children('input').attr('name');
        }else{
            $(this).addClass('checkbox-off');
            $(this).removeClass('checkbox-on');
            $(this).children('input').val(0);
            id=$(this).children('input').attr('name');
        }
        if($.inArray(id,inputs)!=-1){
            inputs.splice($.inArray(id,inputs),1);
            console.log(inputs)
        }else{
            inputs.unshift(id);
            console.log(inputs)
        }
    });
    $('#delete-menu').click(function(){
            if(inputs.length==0){
                $('.hint').html('至少选择一条数据!');
                return;
            }
            $.ajax({
                type:'post',
                data:{data:inputs,deletes:'all'},
                url:'<?= Route::Url('index')?>',
                success:function(response,status,xhr){
                    window.location.reload();
                    //console.log(response);
                }
            });
        }
    );
</script>
</body>
</html>